home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
DA
/
P
/
PCalculator.cpt
/
CalcDA sources
/
CalcDA_FuncStack.c
< prev
next >
Wrap
Text File
|
1990-07-06
|
2KB
|
96 lines
/*
* CalcDA_FuncStack.c for the Programmer's Calculator project
*
* Copyright 1990, Peter Ohler
*
* All Rights Reserved
*
* The Programmer's Calculator and the source code are shareware. That means
* they are not free. If you use either the source or the calculator then
* send $5 or $10 (whatever you feel its worth) to the address that follows.
* The source and calculator can be distributed for free. Prior to any sale
* of either the source code or the calculator my permission must be
* obtained. This includes sales by shareware distribution houses that sell
* shareware.
*
* Peter Ohler
*
* 3184 Rohrer Drive, Lafayette CA 94549
*
* (415) 284-7828
*
* ***************************************************************************
*
* The functions that the user specifies using the button on the calculator
* are not always executed as soon as they are hit. Functions such as +, - ,
* *, etc. are put on a stack and executed when every a function of lower
* presedence is entered. This file contains the functions that manage the
* stack.
*/
#include "CalcDA.h"
/*
* ***************************************************************************
* prototypes
*/
IntFunc PopFuncStack(void);
int PushFuncStack(IntFunc func);
void ClearFuncStack(void);
/*
* ***************************************************************************
* variables
*/
IntFunc funcPending[] = { 0L, 0L, 0L, 0L, 0L};
int funcPendingLen = sizeof funcPending / sizeof(funcPending[0]);
/*
* ***************************************************************************
* functions
*/
/*
* I don't think these functions need much explanation.
*/
IntFunc
PopFuncStack()
{
IntFunc top;
int i;
top = *funcPending;
for (i = 1; i < funcPendingLen; i++) {
funcPending[i - 1] = funcPending[i];
}
funcPending[funcPendingLen - 1] = 0L;
return top;
}
int
PushFuncStack(func)
IntFunc func;
{
int i;
if (0L != funcPending[funcPendingLen - 1])
return -1;
for (i = funcPendingLen - 1; i > 0; i--) {
funcPending[i] = funcPending[i - 1];
}
*funcPending = func;
return 0;
}
void
ClearFuncStack()
{
int i;
for (i = 0; i < funcPendingLen; i++) {
funcPending[i] = 0L;
}
}